<#-- Created by IntelliJ IDEA.
 User: zxm
 Date: 2017/12/19
 Time: 18:00
 To change this template use File | Settings | File Templates.
 角色管理-->
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>日志</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
  <link rel="stylesheet" href="${re.contextPath}/plugin/layui2.2/css/layui.css">
  <link rel="stylesheet" href="${re.contextPath}/plugin/lenos/main.css">
  <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
  <script type="text/javascript" src="${re.contextPath}/plugin/layui2.2/layui.all.js"
          charset="utf-8"></script>
</head>



<body>


<div class="layui-col-md12" style="height:40px;margin-top:40px;padding-left: 30px; border-bottom:0">
  <div class="pink">建议：100KB</div>
  <div class="pink">要求：白背景</div>
  <span>名称</span> <input class="layui-input"  placeholder="请输入签章名称"  style=" display: inline-block;margin-right: 15px;width: 400px;" height="20px" id="fileName" autocomplete="off">
  <div class="layui-btn-group">

     <button type="button" class="layui-btn layui-btn-danger"   onclick="addupload()"><i class="layui-icon"></i>上传图片</button>
    <button type="button"   style="display: none" id="test7"  ></button>
      <div class="layui-inline layui-word-aux">
        这里以限制 100KB 为例
      </div>
    </div>
</div>

<script>
  var  datajson={};
  layui.laytpl.toDateString = function(d, format){
    var date = new Date(d || new Date())
        ,ymd = [
      this.digit(date.getFullYear(), 4)
      ,this.digit(date.getMonth() + 1)
      ,this.digit(date.getDate())
    ]
        ,hms = [
      this.digit(date.getHours())
      ,this.digit(date.getMinutes())
      ,this.digit(date.getSeconds())
    ];

    format = format || 'yyyy-MM-dd HH:mm:ss';

    return format.replace(/yyyy/g, ymd[0])
    .replace(/MM/g, ymd[1])
    .replace(/dd/g, ymd[2])
    .replace(/HH/g, hms[0])
    .replace(/mm/g, hms[1])
    .replace(/ss/g, hms[2]);
  };

  //数字前置补零
  layui.laytpl.digit = function(num, length, end){
    var str = '';
    num = String(num);
    length = length || 2;
    for(var i = num.length; i < length; i++){
      str += '0';
    }
    return num < Math.pow(10, length) ? str + (num|0) : num;
  };

  document.onkeydown = function (e) { // 回车提交表单
    var theEvent = window.event || e;
    var code = theEvent.keyCode || theEvent.which;
    if (code == 13) {
      $(".select .select-on").click();
    }
  }

  function addupload(){

    var fileName = $("#fileName").val();
    if(!fileName.trim()){
      layer.msg("请输入名称" , {icon: 2});
      return  false;
    }
    datajson.fileName=fileName;

    $('#test7').click(); //检查通过再选上传图片

  }

  layui.use(['layer', 'upload',  'table'], function () {
    upload = layui.upload;
    upload.render({
      elem: '#test7'
      ,url: '/sys/sealManager/addFileSeal' //改成您自己的上传接口
      ,size: 300 //限制文件大小，单位 KB
      ,data: datajson
      ,done: function(res){
        layer.msg('上传成功');
        console.log(res)
      }
    });

  });





  layui.use('table', function () {
    var table = layui.table;
    //方法级渲染
    table.render({
      id: 'logList',
      elem: '#logList'
      , url: '/sys/sealManager/queryFileSeal'
      , cols: [[
          {checkbox: true, fixed: true, width: '5%'}
        , {field: 'fileName', title: '名称', width: '60%', sort: true}
        , {field: 'createDate', title: '操作时间', width: '30%',templet: '<div>{{ layui.laytpl.toDateString(d.createTime,"yyyy-MM-dd HH:mm:ss") }}</div>'}

      ]]
      , page: true
      ,  height: 'full-83'
    });

    var $ = layui.$, active = {
      select: function () {
        var userName = $('#userName').val();
        var type = $('#type').val();
        table.reload('logList', {
          where: {
              userName: userName,
              type: type
          }
        });
      }
      ,del:function(){
          var checkStatus = table.checkStatus('logList')
                  , data = checkStatus.data;
          if (data.length ==0) {
              layer.msg('请选择要删除的数据', {icon: 5});
              return false;
          }
          var ids=[];
          for(item in data){
              ids.push(data[item].id);
          }
          del(ids);
        }
      ,add:function(){
        alert(22);

      }
      ,reload:function(){
        $('#userName').val('');
       $('#type').val('');
        table.reload('logList', {
          where: {
              userName: null,
              type: null
          }
        });
      },
    };
    //监听工具条
    table.on('tool(log)', function (obj) {
      var data = obj.data;
      if (obj.event === 'del') {
          var ids=[];
          del(ids.push(data.id));
      }
    });

    $('.layui-col-md12 .layui-btn').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    $('.select .layui-btn').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

  });
  /**批量删除id*/
  function del(ids) {
    $.ajax({
      url: "del",
      type: "post",
      data: {ids: ids},
      dataType: "json", traditional: true,
      success: function (data) {
        layer.msg(data.msg);
        layui.table.reload('logList');
      }
    });
  }
</script>
</body>

</html>
